<template>
  <div style="width:100%;" class="top-con">
    <div class="clearfix">
      <div class="fl fs24 pt10 pb10">云+物娱娃娃机管理后台</div>
      <div class="fr">
        <div class="clearfix">
          <div class="user-info fl">
          <span class="urer-infoin txt-center">
            <i class="fs20">{{username}}</i>
            <i class="fs12 mt5 set-clolor">身份：管理员</i>
          </span>
          </div>
          <div class="user-out fl" @click="userOut()">
            <div class="txt-center mt5">
              <i class="icon iconfont icon-tuichu" style="line-height: 1;"></i>
            </div>
            <div class="fs12 txt-center mt5">
              退出登录
            </div>
          </div>
        </div><!--.clearfix-->
      </div>
    </div>
  </div>
</template>

<script type="text/ecmascript-6">
  import api from '../../assets/js/api';

  export default {
    name: 'topCon',
    data() {
      return {
        username: ''
      }
    },
    mounted: function () {
      this.getUserInfo();
    },
    methods: {
      getUserInfo: function () {
        api.fetch('/api/admin/account')
          .then(res => {
            this.username = res.data.username;
          }).catch();
      },
      userOut: function () {
        api.fetch('/api/admin/account/logout',{method: 'POST'})
          .then(res => {
            window.localStorage.removeItem('token');
            this.$router.push({path: '/login'});
          }).catch();
      }
    }
  }
</script>
<style scoped>
  .top-con {
    background: #438EB9;
    padding: 0 40px;
    box-sizing: border-box;
    color: #fff;
    box-shadow: 2px 0px 2px #024e86;
    top: 0;
    z-index: 2;
    position: fixed;
    top: 0;
  }

  .user-info {
    vertical-align: middle;
    font-size: 0;
    background: #62A8D1;
    height: 44px;
    border-right: 1px solid #E1E1E1;
    padding: 0 8px;
  }

  .user-info span {
    display: inline-block;
    font-size: 0;
    vertical-align: middle;
  }

  .urer-infoin i {
    display: block;
    font-style: normal;
    line-height: 1;
  }

  .urer-infoin i.set-clolor {
    color: #f5f5f5;
  }
  .user-out{
    cursor: pointer;
    vertical-align: middle;
    font-size: 0;
    background: #999;
    height: 44px;
    padding: 0 8px;
  }
</style>
